﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class menu_uc_left_nav_links : DAO.ESWebUserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        InitializeUI();
        if(!Page.IsPostBack)
        {
            LoadLinks();
        }
    }

    private void LoadLinks()
    {
        using (SqlConnection conn = new SqlConnection(DAO.Connection.CONN_STRING1))
        {
            conn.Open();
            using (SqlCommand cmd = new SqlCommand("SELECT * FROM dbo.Fn_GetAllLinks(0, 1000000, 'id', 'asc', " + this.LangId + ") WHERE isActive='true'", conn))
            {
                SqlDataReader dr = null;
                dr = cmd.ExecuteReader();
                HyperLink h;
                while (dr.Read())
                {
                    h = new HyperLink();
                    h.NavigateUrl = "HTTP://" + dr["link"].ToString();
                    h.Target = "_blank";
                    h.Text = ">> " + dr["link_text"].ToString();
                    h.CssClass = "accessoriesLink";
                    phLinks.Controls.Add(
                        new LiteralControl("<div style='width:200px'>"));
                    phLinks.Controls.Add(h);
                    phLinks.Controls.Add(
                        new LiteralControl("</div>"));
                }
            }
        }
    }

    protected override void InitializeUI()
    {
        long langId = DAO.Connection.DEFAULT_LANGUAGE;
        if (Session["language"] != null)
            long.TryParse(Session["language"].ToString(), out langId);

        this.LangId = Convert.ToInt32(langId);
    }
}
